package com.scedu.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

public class ResponseJson {
    /**
     * 返回用户提示
     * @param response
     * @param code 返回编号
     * @param msg 返回提示
     */
    public static void response(HttpServletResponse response,Integer code,String msg) {
        try {
            //未登录提示
            response.setContentType("application/json;charset=utf-8");
            response.setStatus(code);
            PrintWriter out = response.getWriter();
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("code", code);
            map.put("message", msg);
            out.write(new ObjectMapper().writeValueAsString(map));
            out.flush();
            out.close();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
}
